<?php
//简单管理页面范例，在你的管理页面引用coresection/checkA.php就OK，当然，不要忘了添加注销登录的链接

	
include_once '../coresection/checkA.php';

header("Access-Control-Allow-Origin: *"); //解决跨域

    header('Access-Control-Allow-Methods:post');// 响应类型

    date_default_timezone_set('PRC');//获取当前时间

include_once("../../config_controller.php");
$host = $_SERVER['HTTP_HOST']; //取得进入所输入的域名
$theme_folder = host_theme($host);

include_once '../../front/'.$theme_folder.'/connection.php';include_once '../coresection/check_session.php';;
?>

<?php include_once("function.php"); ?>
<?php include "../../front/".$theme_folder."/config.php"; ?>

<?php
if(!isset($_SESSION)){
session_start();
}

$act = $_REQUEST['act'];

$search_val = $_REQUEST['val'];

$result = array('error' => 0, 'message' => '', 'content' => '');


//公用模式
global $table_Prefix;


if ($_REQUEST['act'] == 'upload')
{


 
    $dir1=iconv('UTF-8','gb2312//IGNORE',$_POST['filename']);//用于中文转码
    //ignore的意思是忽略转换时的错误，如果没有ignore参数，所有该字符后面的字符串都无法被保存
    //允许上传的文件扩展名
    $file_type = array( '.mp4' );
    $filetype='.'.substr(strrchr($dir1, "."),1);//截取获得文件后缀名
 
    if(!in_array($filetype,$file_type))
    {
        echo "none";
        return false;
        die;
    }
    $basedir="";
 
    //$dir2=$name.'video_'.time().$filetype;
    $dir=ROOT_PATH_."/uploads/".md5($dir1);
    
	
	//还原文件原名
    file_exists($basedir.$dir) or mkdir($basedir.$dir,0777,true);
    $path=$basedir.$dir."/".$_POST['blobname'];
    //$sql="UPDATE ".$ecs->table('lesson_goods')." SET goods_video='".$dir2."' WHERE goods_id=".$goods_id;
    //echo $sql;die;
    move_uploaded_file($_FILES["file"]["tmp_name"],iconv('UTF-8','gb2312//IGNORE',$path));
 
 
    if(isset($_POST['lastone'])){
      
        //exit();
        $name=ROOT_PATH_."/uploadfiles/".$theme_folder."/";
        if(!is_dir($basedir.$name)){
            mkdir($basedir.$name);
        }
        $dir2=$name.date('Ymd',time()).time().$filetype;
        //var_dump($_POST['videoid']);
 		$video_name = date('Ymd',time()).time().$filetype;
		
        $count=$_POST['lastone'];
        if(!file_exists($basedir.$name)){mkdir($basedir.$name,0777,true);}
        $fp   = fopen($basedir.$dir2,"abw");
        for($i=0;$i<=$count;$i++){
            $handle = fopen($basedir.$dir."/".$i,"rb");
            fwrite($fp,fread($handle,filesize($basedir.$dir."/".$i)));
            fclose($handle);
            @unlink($basedir.$dir."/".$i);
        }
        fclose($fp);
        rmdir($basedir.$dir);
        $video_url="";
        $sql="";
 
        //通过文件是否存在 判断是否上传完成
        if(file_exists($basedir.$name))
        {
            echo $video_name; //'上传完成';
        }
 
    }
}
?>